<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app"></div>

    <template id="my-app">
      <div>
        <h2>{{message}}</h2>
        <h2>{{fullName}}</h2>
        <button @click="changeFullName">change</button>
      </div>
    </template>

    <script src="../vue/vue.js"></script>
    <script>
        const App = {
            template: '#my-app',
            data() {
                return {
                    message: 'hello',
                    firstName: 'leon',
                    lastName: 'Code'
                }
            },
            computed: {
                // fullName的getter方法
                // fullName: function() {
                //     return this.firstName + " " + this.lastName;
                // }

                fullName: {
                    get: function() {
                        return this.firstName + " " + this.lastName;
                    },
                    set: function(newValue) {
                        console.log(newValue);
                        const names = newValue.split(" ");
                        // 拿到的是一个数组
                        this.firstName = names[0];
                        this.lastName = names[1];
                    }
                } 
            },
            methods: {
                changeFullName() {
                    this.fullName = 'xxx a';
                }
            }
        }

        Vue.createApp(App).mount('#app');
    </script>
</body>
</html>